package org.zxp.http;

import java.util.ArrayList;
import java.util.Collection;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @program: effectiveJava
 * @description:
 * @author: X-Pacific zhang
 * @create: 2020-09-10 14:09
 **/
public class Test {
    private static String url = "https://gateway.crpt-cloud.liuheco.com/crpt-fund/fs/hyb/risk/output/model/query";
    private static String charset = "utf-8";
    private static HttpClientUtil httpClientUtil = new HttpClientUtil();
    public static void main(String[] args) throws InterruptedException {
        long begin = System.currentTimeMillis();
        int cCount = 10;
        ExecutorService executor = Executors.newFixedThreadPool(cCount);
        Collection<Callable<Object>> callables = new ArrayList<>(cCount);
        for (int i = 0; i < cCount; i++) {
            callables.add(Test::doPost);
        }
        executor.invokeAll(callables);
        long end = System.currentTimeMillis();
        System.out.println("总时间消耗:"+(end-begin));
    }

    public static Object doPost(){
        long begin = System.currentTimeMillis();
        String httpOrgCreateTest = url;
        String json = "{\n" +
                "    \"data\": \"eyJxdWVyeURhdGUiOiIyMDIwLTA5LTEwIiwicGFnZU5vIjo1LCJwYWdlU2l6ZSI6MTAwfQ==\",\n" +
                "    \"sign\": \"k4sELJkloplZ5uvjSjYGOOTiOpf4SORpudHxwyoI2GY41pyNgRt4tn+ni3L3ZnPSh4XEw84Dn29PGq9Y2GB6+vmPR3xpCN7nkcyUQo22NXb0JFywX2eqgyp7Odizg6YUsxjbP0QPPSubLXnNp6cK1MZKYDSMJLwSZza1lCrMFJw=\"\n" +
                "}";
        String httpOrgCreateTestRtn = httpClientUtil.doPost(httpOrgCreateTest,json);
        long end = System.currentTimeMillis();
        System.out.println(Thread.currentThread().getName()+"消耗时间："+(end-begin));
        return null;
    }
}
